<?
	include_once 'functions.php';
	include 'headermenu.php';

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<!-- <link rel="stylesheet" type="text/css" href="default.css"> -->
<link rel="stylesheet" href="yui.css" type="text/css">
<head>
	
</head>

<body>
<div id="doc" class="yui-t7">

   <div id="bd" role="main">
 
 <div class="yui-gc">
    <div class="yui-u first">
 <!-- PRIMUL ECRAN!!! -->
 	<form action="" name="testQR" method="post" >
	<div align="right">  <input type="submit" name="add" value="Adauga" align="right"> </div>
	</form>

	<?
	$dbh=dbConn();
	//####FUNCTII:
	//####se pare ca daca pun functiile inainte se da refresh la pagina singura!!! si cred ca stiu de ce!
	//####STERGE PROIECT:
	if(isset($_POST['qr_del']))
	{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost sters.");
		mysql_query("delete from projects where id = ".$_GET[rowid].";") or die(mysql_error());
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}

	//####ADAUGA PROIECT:
	if(isset($_POST['qr_add']))
	{
		if($_POST['name'] != null) {
			//echo ("A fost adaugat un nou proiect.");
			mysql_query("INSERT INTO projects(id, name, description, start_date, stop_date, time, user, edit_date) 
			VALUES(null, '".$_POST['name']."', '".$_POST['description']."', now(), now(), '".$_POST['time']."', '".$_POST['user']."', now()); ") or die(mysql_error());  
				unset($_GET[rowid]);
			//refreshPage('http://localhost/methodology/');
		}
	}

	//####MODIFICA PROIECT:
	if(isset($_POST['qr_update']))
	{
		//echo ("Proiectul identificat cu numarul ".$_GET[rowid]." a fost modificat.");
		mysql_query("update projects set name = '".$_POST['name']."',
			description = '".$_POST['description']."',
			start_date = '".$_POST['start_date']."',
			stop_date = '".$_POST['stop_date']."',
			time = '".$_POST['time']."',
			user = '".$_POST['user']."',
			edit_date = '".$_POST['edit_date']."'
			where id = ".$_GET[rowid].";") or die(mysql_error());  
			unset($_GET[rowid]);
		//refreshPage('http://localhost/methodology/');
	}




	$result = returnQuery("Select * from projects;",$dbh);
	//####afisam capu' la tabel:
	echo '<table >';
	echo '<h2><tr>';
		//echo "<td>id</td>";
		echo "<td>name</td>";
		echo "<td>description</td>";
		echo "<td>start_date</td>";
		echo "<td>stop_date</td>";
		echo "<td>time</td>";
		echo "<td>user</td>";
		echo "<td>edit_date</td>";
	echo '</tr></h2>';
	
	//####afisam inregistrarile in tabela:
	while ($row = mysql_fetch_assoc($result)) {
		echo "<tr><p>";
		//echo "<td>".$row["id"]."</td>";
		echo "<td> <a href='index.php?rowid=".$row["id"]."'>".$row["name"]." </a> </td>";
		echo "<td>".$row["description"]."</td>";
		echo "<td>".$row["start_date"]."</td>";
		echo "<td>".$row["stop_date"]."</td>";
		echo "<td>".$row["time"]."</td>";
		echo "<td>".$row["user"]."</td>";
		echo "<td>".$row["edit_date"]."</td>";
		echo "</p></tr>";
	}
	echo('</table>');
	mysql_free_result($result);	
	?>
 

 
     </div>
    <div class="yui-u">
 <!-- AL DOILEA ECRAN!!! -->
 	<?

	
	
		//####afisam sectiunea add/update/delete:
	if(isset($_POST['add'])) 
	{
		unset($_GET[rowid]);
		display($_GET[0]);
	}
	
	//####Functie pentru selectarea unui proiect:
	if (isset($_GET[rowid])!=0)
	{
		
		display($_GET[rowid]);
	}
	
	//####Functie pt butonul Anulare:
	if(isset($_POST['qr_cancel'])) 
	{
			unset($_GET[rowid]);
		refreshPage('http://localhost/methodology/');
	}
	
	//####Inchidem sesiunea DB:
	dbClose($dbh);
	?>

 
 
     </div>
</div>
 


 </div>
    
</div>
</body>
</html>